package com.zatech.cgnci.project.controller.statement;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zatech.cgnci.project.base.context.UserContext;
import com.zatech.cgnci.project.dto.*;
import com.zatech.cgnci.project.entity.UserEntity;
import com.zatech.cgnci.project.service.CgnciProportionalLiabilityInvoiceService;
import com.zatech.cgnci.project.vo.ContractInvoiceDetailsVO;
import com.zatech.cgnci.project.vo.ContractInvoiceVO;
import com.zatech.cgnci.project.vo.LiabilityInvoiceDetailsVO;
import com.zatech.cgnci.project.vo.ProportionalLiabilityInvoiceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 临分摊赔账单信息 前端控制器
 * </p>
 *
 * @author Generator
 * @since 2024-12-30
 */
@RestController
@RequestMapping("/api/proportional-liability")
@Api(produces = "application/json", tags = "临分摊赔账单管理api接口文档")
@RequiredArgsConstructor
public class CgnciProportionalLiabilityInvoiceController {

    @Autowired
    private CgnciProportionalLiabilityInvoiceService proportionalLiabilityInvoiceService;

    @PostMapping("/pageQuery")
    @ApiOperation(value = "分页列表查询")
    public IPage<ProportionalLiabilityInvoiceVO> pageHigherCode(@RequestBody ProportionalLiabilityInvoiceDTO queryDTO) {
        return proportionalLiabilityInvoiceService.pageQuery(queryDTO);
    }

    @GetMapping("/findById")
    @ApiOperation(value = "详情")
    public LiabilityInvoiceDetailsVO findCodeTypeByIdAndNumber(Long id) {
        return proportionalLiabilityInvoiceService.getDetails(id);
    }

    @PostMapping("/addOrUp")
    @ApiOperation(value = "新增Or编辑")
    public void add(@RequestBody @Valid ProportionalLiabilityInvoiceAddDTO addDTO) {
        UserEntity user = UserContext.getUser();
        addDTO.setUser(user.getNameAndCode());
        proportionalLiabilityInvoiceService.addContractInvoice(addDTO);
    }

    @PostMapping("/updateUpm")
    @ApiOperation(value = "更新UPM")
    public void updateUpm(@RequestBody ContractInvoiceUpmUpDTO updateDTO) {
        proportionalLiabilityInvoiceService.updateUpm(updateDTO);
    }

    @GetMapping("/del")
    @ApiOperation(value = "删除")
    @Transactional(rollbackFor = Exception.class)
    public void del(Long id,String invoiceNumber) {
        proportionalLiabilityInvoiceService.delete(id,invoiceNumber);
    }
}

